<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let obj = {
      name: "why",
      age: 18,
      height: 1.88
    }
    // 1、创建一个Proxy对象
    const objProxy = new Proxy(obj, {
      // set捕获器
      set: function (target, key, newValue) {
        console.log(`设置了${key}的值:`, newValue)
        target[key] = newValue
      },
       // get捕获器
      get: function (target, key) {
        console.log(`获取${key}的值`)
        return target[key]
      }
    })
    // 2、对obj的所有操作，应该去操作objProxy
    console.log(objProxy.name)
    console.log(objProxy.age)
    objProxy.address = '广州市'
  </script>

</body>

</html>